# coding: utf-8
import random

str = 'helloworld'
print('o' in str)
print('b' not in str)
print(len(str))
print(max(str))
print(min(str))
# for e in str:
#     print(ord(e), e)

print(str.index('o'))
print(str.count('o'))

# 创建列表  ------>数组
print('-' * 20, '列表（数组）开始', '-' * 20)
arr = ['hello', 'world', 'asdsa']
arr1 = list(str)
arr2 = list(range(1, 10, 2))
# del arr2
print(arr, arr1, arr2)
print(id(arr))
for e in arr:
    print(e)
for i in range(len(arr)):
    print(i, arr[i])
# 下标从1开始
for i, e in enumerate(arr, 1):
    print(i, e)

arr.append('zxc')
arr.insert(1, 'qwe')
print('insert', arr)
# arr.clear()
# print(arr)
print(arr.pop(2))
print('pop', arr)
arr.remove('qwe')
print('remove', arr)

arr.reverse()
print('reverse', arr)
# arr.reverse(2)
# print('reverse', arr)
print(id(arr))

arr3 = arr.copy()
print('copy', arr3)

# 忽略大小写
arr.sort(key=lambda x: x.lower())
print('sort', arr)
arr.sort(reverse=True)
print('sort', arr)

arr4 = sorted(arr)
print(arr4)

arr5 = [c for c in range(1, 10) if c % 2]
print(arr5)

arr6 = [[j for j in range(6)] for c in range(5)]
print(arr6)

print('-' * 20, '列表（数组）结束', '-' * 20, '\n')

print('-' * 20, '元组（比列表（数组）快）可重复 开始', '-' * 20)
t = ('hello', 'python')
print(t)

t = tuple('hello')
print(t)

t = tuple([10, 22, 33])
print(t)

print(22 in t)
print(11 not in t)
print(len(t))
print(max(t))
print(min(t))
for e in t:
    print(e)

print(t.index(22))
print(t.count(22))

p = (i for i in range(1, 10))
print(p)
print(p.__next__())
print(p.__next__())

p = tuple(p)
print(p)

print('-' * 20, '元组 结束', '-' * 20, '\n')

print('-' * 20, '字典 开始', '-' * 20)
d = {
    'name': 'zhangsan',
    'age': 18,
}
print(d)

d = zip(['a', 'b', 'c'], [1, 2, 3])
print(d)
print(list(d))

d = dict(a=4, b=6, c=2)
print(d)

# 元组可以为key值 列表不可以  key键是无序的
print({p: 20})
# print({arr5: 30})
print('max', max(d))
print('min', min(d))
print('len', len(d))

print(d['a'])
print(d.get('a'))
print(d.get('d', '不存在'))

print('获取所有的key', d.keys())
print('获取所有的value', d.values())
print('key存在获取相应的value,同时删除key-value对，否则获取默认值', d.pop('a', '不存在'))
print('随机获取一个key-value对，并删除', d.popitem())
d.clear()  # 清空字典

d = {i: random.randint(1, 100) for i in range(1, 10)}
print(d)

lst = [1001, 1002, 1003]
lst1 = ['a', 'w', 'g']
d = {i: j for i, j in zip(lst, lst1)}
print(d)
print('-' * 20, '字典 结束', '-' * 20, '\n')

print('-' * 20, '集合（无序不重复） 开始', '-' * 20)
s = {1, 2, 3, 4, 5}
print(s)

# 创建空集合 用{}为字典
s1 = set()
print(s1)
print('max', max(s))
print('min', min(s))
print('len', len(s))
print(9 in s)
print(11 not in s)

s2 = {2, 4, 6, 8}
print(s & s2)
print(s | s2)
print(s - s2)
print(s ^ s2)

s2.add(9)
print(s2)
s2.remove(6)
print(s2)
s2.clear()
print(s2)
s2 = {i for i in range(1, 10)}
print(s2)
print('-' * 20, '集合 结束', '-' * 20, '\n')